remotemanager.connection.computers.dynamicvalue module¶
DynamicValue stub class allows for deferred calculation of values.
Constructing a “tree” of values using these objects allows for later assessment. Used in Computers for dynamic resource assignment.
>>> val_a = DynamicValue(10)
>>> val_b = DynamicValue(6)
>>> val_c = DynamicValue(val_a + val_b)
>>> val_c.value
16
- class remotemanager.connection.computers.dynamicvalue.ChainingMixin[source]¶
Adds chaining ability for DynamicMixin and DynamicValue
- property shortform_op: str | None¶
Returns the operator in a readable form for calc insertion
eg +, -, * instead of add, sub, mul, etc.
- class remotemanager.connection.computers.dynamicvalue.DynamicMixin(assignment: str | None = None, default: Any | None = None, value: Any | None = None, optional: bool = True, requires: str | list | None = None, replaces: str | list | None = None, hidden: bool = False, min: int | None = None, max: int | None = None, format: str | None = None, empty_treatment: str = 'line', static: bool = False)[source]¶
Provides functions to enable Entities using DynamicValue to chain properly
Important
The DynamicValue in question must be directly available at _value
- Parameters:
assignment (str) – The variable to which this object is assigned, for introspection
default (Any, None) – Default value, marks this Resource as optional if present
value (Any, None) – Sets the value directly. You should ideally set the default, as this is easy to override and break
optional (bool) –
Marks this resource as Optional. Required as there are actually three states:
Required input, required by scheduler.
Optional input, required by scheduler.
Optional input, optional by scheduler.
requires (str, list) – Stores the name(s) of another variable which is required alongside this one
replaces (str, list) – Stores the name(s) of another variable which is replaced by this one
hidden (bool) – The value will be present, but requests to not be displayed
min (int) – Minimum value for numeric inputs
max (int) – Maximum value for numeric inputs
format (str) – Expected format for number. Allows None, “time” or “float”
empty_treatment (bool) –
Dictates how an empty value is treated. Possible options are: - line
default, removes the whole line
- local
locally removes the output
- ignore
does nothing, leaves the output unchanged
static (bool) – Does not chain with other values if True
- property name: str¶
Returns the name under which this resource is stored
- property min: int | None¶
Minimal numeric value
- property max: int | None¶
Maximal numeric value
- property default¶
Returns the default, if available
- property optional¶
Returns True if this Resource is optional at Dataset level
- property replaces: list¶
List of arguments whom are no longer considered required if this resource is specified
- property requires: list¶
List of requirements if this resource is specified. e.g. nodes for mpi_per_node
- property empty_treatment¶
Dictates how this parameter is treated if it is empty.
Possible behaviours:
line
:This is the default, and deletes the whole line. Useful when parameterising resource requests such as
#SBATCH nodes=#nodes#
local
:Locally deletes the value, leaving the remainder of the line. Note that this does not delete anything _outside_ of the extents of the parameter. For example:
#SBATCH nodes=#NODES:empty_treatment=local#
->#SBATCH nodes=
Useful when arguments may follow one another:
#a:empty_treatment=local# #b:empty_treatment=local#
In this case, a missing
a
orb
will not delete the otherignore
:Disables any treatment, values will be left as is:
#a=#a:empty_treatment=local#
->#a=#a:empty_treatment=local#
- property value¶
Attempt to safely return the value (default) from self
- property linked: bool¶
Returns True if this Value has been linked by Script
- set_value(value)[source]¶
Sets the value, separating out the function allows for property overloading
Since this function handles value setting for both Resource/Substitution AND the DynamicValues within, we have some extra edge cases to catch
- case 1
We have a resource, and are setting the value to a static int
- case 2
We have a resource and are setting the value to directly mirror another resource
- case 3
We have a resource and are setting the value to be a combination of other resources (DV)
- class remotemanager.connection.computers.dynamicvalue.DynamicValue(a: Number | DynamicValue | None, b: Number | DynamicValue | None = None, op: str | None = None, default: Number | DynamicValue | None = None, assignment: str | None = None)[source]¶
- Parameters:
a – “First” number in operation
b – “Second” number in operation. Can be None, in which case this value is considered “toplevel”
op – Operation to use. Can be None for toplevel values
default – Default value can be set in case the primary value is set to None
- property a¶
Returns: Value of “first” number
- property b¶
Returns: Value of “second” number
- property op¶
Returns: Operation string
- property default¶
Returns: The default value
- property assignment: str | None¶
The variable at which this value is assigned, if available
- property static: bool¶
Returns True if this Dynamic variable is static, rather than dynamic
- property value¶
Calculates value by calling the whole chain of numbers
- Returns:
Value
- property reduced: str¶
Returns the string form “reduced” version of this DynamicValue.
In theory this should be storable as text within a database, without losing dependency information
Extracts details from the assignment, if provided. Else returns the value.
e.g. .. code:: python
a = Resource(name=”a”) b = Resource(name=”b”) c = Resource(name=”c”)
c = a + b
c.reduce > “(a + b)”
- remotemanager.connection.computers.dynamicvalue.treat_for_storage(var: Any) str [source]¶
Ensures that var is stored properly
Strings must be quoted, but _not_ those that are actually ints
- remotemanager.connection.computers.dynamicvalue.concat_basic(a: int | DynamicValue | Resource | Substitution, b: int | DynamicValue | Resource | Substitution) DynamicValue [source]¶
Concat two values a and b
Required in the case where we want to add a value to a string
Since str + Resource will call the __add__ method of the str object, we get a TypeError
We need to sidestep this by adding the string to the _value_, then reversing the value.
Doing it this way calls the corrent DynamicMixin.__add__(…) function, rather than str.__add__(…)
- ..note::
This function will at least _try_ to return a+b beforehand
- Parameters:
a – first value
b – second value
- Returns:
a+b